<template>
	<div class="pages">
		<div class="search">
			<van-search background="#4674C9" @click-right-icon="searchLists" v-model="search" left-icon="" right-icon="search"
				placeholder="请输入搜索关键词" />
		</div>
		<div class="date-preview">
			<div class="item bg-green">
				<div class="content">
					<div class="icon bg-green">
						<img src="../../../assets/imgs/taskPreview/icon-yfk.png">
					</div>
					<div class="text">
						<span class="label">已反馈</span>
						<span class="circle">·</span>
						<span class="value" v-text="datePreview.yfk"></span>
					</div>
				</div>
				<div class="to">
					<van-icon name="upgrade" size="20px" color="#07A43B" />
				</div>
			</div>
			<div class="item bg-blue">
				<div class="content">
					<div class="icon bg-blue">
						<img src="../../../assets/imgs/taskPreview/icon-yfk.png">
					</div>
					<div class="text">
						<span class="label">办理中</span>
						<span class="circle">·</span>
						<span class="value" v-text="datePreview.yfk"></span>
					</div>
				</div>
				<div class="to">
					<van-icon name="upgrade" size="20px" color="#4C69DC" />
				</div>
			</div>
			<div class="item bg-yellow">
				<div class="content">
					<div class="icon bg-yellow">
						<img src="../../../assets/imgs/taskPreview/icon-yfk.png">
					</div>
					<div class="text">
						<span class="label">待反馈</span>
						<span class="circle">·</span>
						<span class="value" v-text="datePreview.yfk"></span>
					</div>
				</div>
				<div class="to">
					<van-icon name="upgrade" size="20px" color="#F3A000" />
				</div>
			</div>
			<div class="item bg-yellow">
				<div class="content">
					<div class="icon bg-yellow">
						<img src="../../../assets/imgs/taskPreview/icon-yfk.png">
					</div>
					<div class="text">
						<span class="label">待办理</span>
						<span class="circle">·</span>
						<span class="value" v-text="datePreview.yfk"></span>
					</div>
				</div>
				<div class="to">
					<van-icon name="upgrade" size="20px" color="#F3A000" />
				</div>
			</div>
		</div>
		<div class="container">
			<!-- 发送平台 star -->
			<div class="lists-module-tips">
				<div class="lists">
					<van-pull-refresh class="pull-refresh" v-model="lists.refresh.loading" @refresh="onRefresh">
						<van-list v-model:loading="lists.more.loading" :finished="lists.more.finished" finished-text="没有更多了"
							@load="onLoad">
							<van-checkbox-group v-model="checked">
								<div class="item" @click="toPage(paths.platfromInfo)" v-for="(item, idx) in lists.lists" :key="idx">
									<div class="info">
										<van-checkbox shape="square" icon-size="12px" :name="idx"></van-checkbox>
										<div class="text">
											<div class="content" v-text="item.name"></div>
											<div class="label text-overflow">
												<span class="company" v-text="'接收人：' + item.user"></span>
												<span class="state">任务状态：<span :class="{
												'state-color-blue': item.state === '2',
												'state-color-yellow': item.state === '3',
												'state-color-green': item.state === '1',
												}" v-text="formatStatus(item.state)" /></span>
											</div>
										</div>
									</div>
									<van-divider />
								</div>
							</van-checkbox-group>
						</van-list>
					</van-pull-refresh>
				</div>
			</div>
			<van-popup v-model:show="lists.detail.show" position="bottom" close-on-popstate :style="{ height: '30%' }">
				<div class="popup-container">
					<div class="tools">
						<div class="cancel" @click="lists.detail.show = false">取消</div>
						<div class="del">删除信息</div>
					</div>
					<van-divider class="line" />
					<div class="content">
						<div class="text">
							<div class="title" v-text="'平台名称：'"></div>
							<div class="value" v-text="lists.detail.info.name"></div>
						</div>
						<div class="text">
							<div class="title" v-text="'属地单位：'"></div>
							<div class="value" v-text="lists.detail.info.company"></div>
						</div>
						<div class="text">
							<div class="title" v-text="'接收人：'"></div>
							<div class="value" v-text="lists.detail.info.user"></div>
						</div>
						<div class="text">
							<div class="title" v-text="'联系方式：'"></div>
							<div class="value" v-text="lists.detail.info.phone"></div>
						</div>
					</div>
				</div>
			</van-popup>
			<!-- 发送平台 end -->
		</div>
		<div class="menu">
			<div class="btn blue btn-w-3">属地催办</div>
			<div class="btn blue btn-w-3">企业催办</div>
			<div class="btn blue btn-w-3">批量导出</div>
		</div>
	</div>
</template>

<script lang="ts" setup>
import { ref, reactive, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import '@/styles/font/stylesheet.css'

const route = useRoute();
const router = useRouter();

// 搜索
const search = ref('');
const searchLists = () => {
	// console.log('search', search.value);
}

const datePreview = reactive({
	yfk: 123,
	blz: 123,
	dfk: 123,
	dbl: 123,
})

const lists = reactive({
	refresh: {
		loading: false
	},
	more: {
		loading: false,
		finished: false
	},
	lists: [] as any,
	detail: {
		show: false,
		info: {
			name: '',
			user: '',
			company: '',
			phone: ''
		}
	}
})

// 选中列表
const checked = ref([]);

// 下拉刷新回调
const onRefresh = () => {
	// 清空列表数据
	lists.more.finished = false;

	// 重新加载数据
	// 将 loading 设置为 true，表示处于加载状态
	lists.more.loading = true;
	onLoad();
}

// 加载更多回调
const onLoad = () => {
	setTimeout(() => {
		if (lists.refresh.loading) {
			lists.lists = [];
			lists.refresh.loading = false;
		}

		let temp = [{
			name: '北京百度网讯科技有限公司',
			user: '王一',
			state: '1',
			company: '北京市市场监督管理局',
			phone: '18312870978'
		}, {
			name: '北京百度网讯科技有限公司',
			user: '王二',
			state: '1',
			company: '北京市市场监督管理局',
			phone: '18312870978'
		}, {
			name: '北京百度网讯科技有限公司',
			user: '王三',
			state: '1',
			company: '北京市市场监督管理局',
			phone: '18312870978'
		}, {
			name: '北京百度网讯科技有限公司',
			user: '王四',
			state: '2',
			company: '北京市市场监督管理局',
			phone: '18312870978'
		}, {
			name: '北京百度网讯科技有限公司',
			user: '王一',
			state: '2',
			company: '北京市市场监督管理局',
			phone: '18312870978'
		}, {
			name: '北京百度网讯科技有限公司',
			user: '王一',
			state: '3',
			company: '北京市市场监督管理局',
			phone: '18312870978'
		}, {
			name: '北京百度网讯科技有限公司',
			user: '王一',
			state: '3',
			company: '北京市市场监督管理局',
			phone: '18312870978'
		}, {
			name: '北京百度网讯科技有限公司',
			user: '王一',
			state: '3',
			company: '北京市市场监督管理局',
			phone: '18312870978'
		}, {
			name: '北京百度网讯科技有限公司',
			user: '王一',
			state: '3',
			company: '北京市市场监督管理局',
			phone: '18312870978'
		}];
		lists.lists.push(...temp);
		lists.more.loading = false;

		if (lists.lists.length >= 40) {
			lists.more.finished = true;
		} else {
			lists.more.finished = false;
		}
	}, 1000);
}

const formatStatus = (status:any) => {
	switch(status) {
		case '1':
			return '已反馈';
		case '2':
			return '办理中';
		case '3':
			return '待办理';
	}
}

const paths = reactive({
	platfromInfo: '/reportpreview/reportplatfrominfo',
})

const toPage = (path: any, params: any = {}) => {
	router.push({ path, query: params })
}
onMounted(() => {
})
</script>
<style lang="scss" scoped>
.pages {
	height: 100%;
	display: flex;
	flex-direction: column;

	.date-preview {
		background: #ffffff;
		box-shadow: 0.5px 0.87px 4.5px 1px rgba(0,0,0,0.05);
		box-sizing: border-box;
		padding: 16px 12px;
		display: grid;
		grid-template-rows: repeat(2, minmax(0,1fr));
		grid-template-columns: repeat(2, minmax(0,1fr));
		grid-gap: 10px;

		.item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			box-sizing: border-box;
			padding: 8px 10px;
			.content {
				display: flex;
				align-items: center;
				.icon {
					width: 21px;
					height: 21px;
					margin-right: 10px;
					display: flex;
					align-items: center;
					justify-content: center;
					img {
						width: 10px;
						height: 10px;
					}
				}

				.bg-green {
					background-color: #07A43B;
				}
				.bg-blue {
					background-color: #4C69DC;
				}
				.bg-yellow {
					background-color: #F3A000;
				}

				.text {
					display: flex;
					align-items: center;
					.label {
						font-size: 14px;
						font-weight: bold;
						color: #181818;
					}
					.circle {
						font-size: 14px;
						font-weight: bold;
						color: #181818;
						margin: 0 5px;
					}
					.value {
						font-size: 18px;
						font-family: 'lcd';
						margin-bottom: 2px;
						letter-spacing: 2px;
						font-weight: bold;
						color: #181818;
					}
				}
			}

			.to {
				&::v-deep(.van-icon) {
					transform: rotate(90deg);
				}
			}
		}

		.bg-green {
			background-color: #E9FFEB;
		}
		.bg-blue {
			background-color: #F1F4FF;
		}
		.bg-yellow {
			background-color: #FFFBED;
		}
	}

	.container {
		flex: 1;
		height: 0;
		box-sizing: border-box;
		padding: 12px;
		display: flex;
		flex-direction: column;

		// 列表模板-提示
		.lists-module-tips {
			background: #ffffff;
			border-radius: 5px;
			box-shadow: 0.5px 0.87px 4.5px 1px rgba(0, 0, 0, 0.05);
			box-sizing: border-box;
			flex: 1;
			height: 0;
			overflow-y: scroll;

			.lists {
				padding-top: 16px;

				.item {
					display: flex;
					flex-direction: column;
					padding: 0 12px 0 12px;

					.info {
						display: flex;
						flex-direction: row;

						.circle {
							width: 4px;
							height: 4px;
							background-color: $primary-color;
							border-radius: 50%;
							margin-top: 6px;
							margin-right: 8px;
						}

						&:deep(.van-checkbox) {
							align-items: flex-start;
							margin-top: 2px;
							margin-right: 8px;

							.van-checkbox__icon--checked {
								.van-icon {
									background-color: $primary-color;
									border-color: $primary-color;
								}
							}

							.van-icon-success:before {
								position: absolute;
								left: 50%;
								height: 50%;
								transform: translate(-50%, -50%);
							}
						}

						.text {
							flex: 1;

							.content {
								font-size: 14px;
								font-weight: bold;
								text-align: left;
								color: #181818;
								margin-bottom: 8px;
							}

							.label {
								font-size: 10px;
								font-weight: bold;
								color: #646464;
								white-space: nowrap;
								display: flex;
								align-items: center;

								.company {
									margin-right: 40px;
								}

								.state {
									
								}

								.state-color-blue {
									color: $primary-color;
								}
								.state-color-green {
									color: #07A43B;
								}
								.state-color-yellow {
									color: #F3A000;
								}

								.detail {
									color: $primary-color;
								}
							}
						}
					}
				}
			}
		}
	}

	.popup-container {
		.tools {
			display: flex;
			align-items: center;
			justify-content: space-between;
			box-sizing: border-box;
			padding: 9px 12px;

			.cancel {
				font-size: 14px;
				font-weight: bold;
				color: #646464;
			}

			.del {
				font-size: 14px;
				font-weight: bold;
				color: #ef0d0d;
			}
		}

		.line {
			margin-top: 0;
		}

		.content {
			box-sizing: border-box;
			padding: 16px 24px;

			.text {
				display: flex;
				align-items: center;
				margin-bottom: 16px;

				&:last-child {
					margin-bottom: 0;
				}

				.title {
					font-size: 14px;
					font-weight: bold;
					color: #181818;
				}

				.value {
					font-size: 14px;
					font-weight: bold;
					color: #646464;
				}
			}
		}
	}

	.menu {
		display: flex;
		align-items: center;
		justify-content: space-evenly;
		box-sizing: border-box;
		padding: 10px 0;
		background: #ffffff;
		box-shadow: 0px -1px 2.5px 1px rgba(0, 0, 0, 0.03), -0.5px 0px 0px 0.5px #ebebeb inset;

		.btn {
			box-sizing: border-box;
			padding: 8px 0;
			border-radius: 5px;
			font-size: 14px;
			font-weight: bold;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.btn-w-3 {
			width: 30%;
		}

		.btn-w-2 {
			width: 45%;
		}

		.blue {
			color: $primary-color;
			background-color: #F1F4FF;
		}

		.red {
			color: #EF0D0D;
			background-color: #FFF1F2;
		}
	}
}
</style>